# coding: utf-8
from datetime import datetime

from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.http import HttpResponseServerError
from django.shortcuts import render
from django.urls import reverse
from django.views import View
from leancloud import Object
from leancloud import Query
from leancloud.errors import LeanCloudError

class ItemSort(Object):
    pass

class ItemSortView(View):
    def get(self, request):
        try:
            item_sort_info = Query(ItemSort).descending('createdAt').find()
        except LeanCloudError as e:
            if e.code == 101: 
                item_sort = []
            else:
                raise e
        item_sort = []
        for item_info in item_sort_info:
            item_sort.append({
                "ItemName": item_sort_info.get("ItemName"), 
                "SortName": item_sort_info.get("SortName")
            })
        return render(request, 'item_sort.html', {
            'itemSort': [{"ItemName": 1, "SortName": 2}],
        })


